<!DOCTYPE html>
<html>
    <head>
        <!-- 当前文档的字符集编码为utf-8 -->
        <meta charset="utf-8">
        <meta name = "author" content="wyrQF">
        <meta name="keywords" content="CGI开发 H5模版 千锋教育 西安物联网">
        <title>测试姓名得分</title>
        <link rel="stylesheet" href="/css/my.css">
    </head>
    <body>
        <div>
            <input type="text" placeholder="请输入您的姓名" id="inputName">
            <button onclick="capScore()">得分</button>
        </div>
        <div id="ret"></div>

        <script>
            let names = [];
            let scores = [];
            function capScore(){
                // 获取输入的姓名
                let name = inputName.value;
                // 查询此姓名是否已经测试
                let idx = names.indexOf(name);
                let score = 100;
                
                if(idx == -1){
                    // 不存在
                    names.push(name);

                    // 随机产生一个分数
                    score = parseInt(Math.random() *(100-85+1)+85);
                    scores.push(score);// 得分添加进数组
                }
                else{
                    // 存在
                    score = scores[idx];
                }
                if(score > 95){
                    // ret.innerHTML = "<h3 style='color:red;''>"+score+"</h3>";
                    ret.innerHTML = "<img src='/img/GULULU-冰奶昔.png width='30px' height='30px'>";
                }
                else{
                    ret.innerHTML = "<h3 style='color:aqua;''>"+score+"</h3>";
                }
                
            }
        </script>
    </body>
</html>
